//
//  RoomTimeView.m
//  QRMaster
//
//  Created by myApple on 15/8/21.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "RoomTimeView.h"
#import "setTimeModel.h"
#import "PromptInfoView.h"
#import "SetDateTimeCell.h"

@interface RoomTimeView ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * timeTableView;
    NSMutableArray * timeDataArray;
    NSArray * weakData;
    UIActivityIndicatorView * _activityIndicator;
}

@end

@implementation RoomTimeView

- (id) initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        [self awakeFromNib];
    }
    timeDataArray = [[NSMutableArray alloc]init];
    weakData = @[NSLocalizedString(@"Sunday", nil),NSLocalizedString(@"Monday", nil),NSLocalizedString(@"Tuesday", nil),NSLocalizedString(@"Wednesday", nil),NSLocalizedString(@"Thursday", nil),NSLocalizedString(@"Friday", nil),NSLocalizedString(@"Saturday", nil)];
    return self;
}

-(void)setTimeData:(NSMutableArray *)timeData
{
    _timeData = timeData;
    timeDataArray = timeData;
    [self prepareTableView];
}

-(void)prepareTableView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float ScreenHeight = [UIScreen mainScreen].bounds.size.height;
    float x = 0;
    float y = 5;
    float width = ScreenWidth;
    float height = ScreenHeight - y;
    
    timeTableView = [[UITableView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    timeTableView.dataSource = self;
    timeTableView.delegate = self;
    timeTableView.bounces = NO;
    [self addSubview:timeTableView];
    
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 30)];
    timeTableView.tableHeaderView = headView;
    UILabel * headLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 20)];
    headLabel.text = NSLocalizedString(@"getCardTime",nil);
    headLabel.font = [UIFont systemFontOfSize:16.0];
    headLabel.textAlignment = NSTextAlignmentCenter;
    [headView addSubview:headLabel];
    
    UILabel * footLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, timeTableView.frame.size.width, 40)];
    footLabel.text = NSLocalizedString(@"openRoomTime", nil);
    footLabel.numberOfLines = 0;
    footLabel.font = [UIFont systemFontOfSize:16.0];
//    footLabel.textAlignment = NSTextAlignmentCenter;
    timeTableView.tableFooterView = footLabel;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return timeDataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * string = @"cell";
    SetDateTimeCell * cell = [tableView dequeueReusableCellWithIdentifier:string];
    if (!cell) {
        cell = [[SetDateTimeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];
    }
    if (timeDataArray.count > indexPath.row) {
        setTimeModel * model = timeDataArray[indexPath.row];
        cell.beginTime = model.beginTime;
        cell.endTime = model.endTime;
        cell.weekInfo = model.weekInfo;
        cell.showSwitch = NO;
    }
    return cell;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
